﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<EGym.BL.Forms.AlunoForm>" %>
<%@ Import Namespace="EGym.Controllers"%>

<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
    eGym - Relação de Alunos
</asp:Content>
<asp:Content ID="scriptContainer" ContentPlaceHolderID="ScriptContent" runat="server">

    <script type="text/javascript">
        var TAB_MAIN = "#tabMain";
        var afiliadoId = <%= SessionManager.Usuario.AfiliadoId %>;
        //Inicialização de componentes globais.
        $(function() {
            associaEventos();

        });


        function associaEventos(item) {
            if (item == null) {
                $(".imageButton").click(buttonClick);
                $("#dialogEntryForm").submit(dialogEntrySubmit);
            }
            else {
                $(item + " .imageButton").click(buttonClick);
            }

        }
        function buttonClick() {
            switch ($(this).attr("id")) {
                case "dialogEntrySave":
                    {
                        $("#dialogEntryForm").submit();
                        break;
                    }
                default:
                    {
                        if ($(this).attr("id") != "" && $(this).attr("id") != null)
                            alert($(this).attr("id"));
                        break;
                    }
            }
        }


        function dialogEntrySubmit() {
            $(this).ajaxSubmit();
            // return false to prevent normal browser submit and page navigation 
            return false;

        }
        function postDialogEntry() {
            $("dialogEntryForm").submit();
            return;
            $.ajax({
                url: "/Aluno/Search",
                data: { text: $("#TextoPesquisado").val() },
                type: "post",
                dataType: "json",
                beforeSend: function(XMLHttpRequest) {
                    $("#loadingSpinner").show();
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert('Erro....');
                },
                success: function(data, textStatus, XMLHttpRequest) {
                    $("#loadingSpinner").hide();
                }
            });
        }

        function editEntry(id) {
            loadDataEntry(id);
            //alert(id);
        }
        
        /*
            getById(urlDataRequest, idText, callbackForBeforeSend, callbackForError, callbackForSucess)
        */
        
        function loadDataEntry(id) {
            var urlDataRequest = "/Aluno/GetJsonResultById";
            var idText = afiliadoId + "," + id;
            
            var entry = getById(urlDataRequest,idText);
            
            
            if (entry != null){
                $("#Aluno_Nome").val(entry.Nome);
                $("#Aluno_DataCadastro").val(entry.DataCadastro);
                $("#Aluno_DataNascimento").val(entry.DataNascimento);
                $("#Aluno_Email").val(entry.Email);
                $("#Aluno_TwitterAccount").val(entry.TwitterAccount);
                
                maximizaElemento("#dialogEntry");
                $("#dialogEntry").dialog("open");
            }
            
        }
    
    </script>

</asp:Content>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    <table class="fullContainer">
        <tr>
            <td>
                <% Html.RenderPartial("MenuAluno"); %>
            </td>
            <td>
                <% Html.RenderPartial("Lista"); %>
            </td>
        </tr>
    </table>
    <% Html.RenderPartial("Entrada"); %>
    <script type="text/javascript">
        var idSelecionado = 0;
        $(document).ready(function() {

            createCustomButtons();
        }
        );
        function createCustomButtons() {
            $("#grdAlunoMain").jqGrid('navButtonAdd', '#grdAlunoMain_pager',
            {
                caption: "Botão Customizado",
                onClickButton: function() {
                    editEntry(idSelecionado);
                }

            });
        }

        function grdAlunoMain_onRowSelected(id) {
            idSelecionado =id ;
        }

    
    </script>
</asp:Content>
